package net.monare.mifss.admin.ui.win;

import com.vaadin.ui.*;
import com.vaadin.ui.themes.Runo;
import net.monare.mifss.MifssMessages;
import net.monare.mifss.admin.ui.mod.PoolDefUiModule;
import net.monare.mifss.configurations.pojo.ContentPoolDef;
import net.monare.mifss.configurations.pojo.StorageDef;
import net.monare.mifss.evn.AddNewPoolDefinitionListener;
import net.monare.mifss.evn.UpdatePoolDefinitionListener;

/**
 * Created by jernej on 4/2/14.
 */
public class ConfigureStoragePoolWindow extends Window {

    public ConfigureStoragePoolWindow(ConfigureStorageWindow parent, ContentPoolDef contentPoolDef, StorageDef storageDef){

        PoolDefUiModule pdui = null;
        NativeButton poolButton = null;
        Label rpTitle = null;

        VerticalLayout verticalLayout = new VerticalLayout();
        verticalLayout.setSpacing(true);
        verticalLayout.setMargin(true);
        verticalLayout.setSizeFull();

        VerticalLayout formBar = new VerticalLayout();
        VerticalLayout buttonBar = new VerticalLayout();



        if (contentPoolDef != null) {
            rpTitle = new Label(MifssMessages.getMessage("tile.pool.configuration"));

            pdui = new PoolDefUiModule(contentPoolDef);
            pdui.protectFields();
            poolButton = new NativeButton(MifssMessages.getMessage("button.update.pool"));
            poolButton.addClickListener(new UpdatePoolDefinitionListener(storageDef, pdui, parent, this));

        } else {

            rpTitle = new Label(MifssMessages.getMessage("tile.pool.add"));
            pdui = new PoolDefUiModule();
            poolButton = new NativeButton(MifssMessages.getMessage("button.add.new.pool"));
            poolButton.addClickListener(new AddNewPoolDefinitionListener(storageDef, pdui, parent, this));

        }

        rpTitle.setStyleName(Runo.LABEL_H1);
        formBar.addComponent(rpTitle);
        formBar.addComponent(pdui);
        verticalLayout.addComponent(formBar);
        buttonBar.addComponent(poolButton);
        buttonBar.setComponentAlignment(poolButton, Alignment.BOTTOM_RIGHT);
        verticalLayout.addComponent(buttonBar);
        verticalLayout.setComponentAlignment(buttonBar, Alignment.BOTTOM_RIGHT);

        setStyleName(Runo.WINDOW_DIALOG);
        setWidth("650px");
        setHeight("450px");
        setModal(true);
        setContent(verticalLayout);

    }

}
